<?php

use Illuminate\Support\Facades\Schema;
use Illuminate\Database\Schema\Blueprint;
use Illuminate\Database\Migrations\Migration;

class CreateStoreOrdersTables extends Migration
{
    /**
     * Run the migrations.
     *
     * @return void
     */
    public function up()
    {
        //订单
        Schema::create('orders', function (Blueprint $table) {
            $table->engine = 'InnoDB';
            $table->increments('id');
            $table->string('openid')->comment('微信openid');
            $table->tinyInteger('order_type')->nullable()->comment('订单类型');
            $table->string('order_number')->nullable()->comment('订单编号');
            $table->decimal('order_price',8,2)->nullable()->comment('订单金额');
            $table->tinyInteger('order_status')->nullable()->comment('订单状态');
            $table->tinyInteger('pay_status')->nullable()->comment('支付状态');
            $table->text('goods_info')->nullable()->comment('商品信息');
            $table->text('service_info')->nullable()->comment('服务信息');
            $table->string('order_remark')->nullable()->comment('订单备注');
            $table->integer('hotel_id')->unsigned()->index('hotel_id')->comment('酒店外键id');
            $table->integer('room_id')->unsigned()->index('room_id')->comment('房间外键id');
            $table->timestamps();

            $table->foreign('hotel_id')
                  ->references('id')
                  ->on('hotels')
                  ->onDelete('cascade');

            $table->foreign('room_id')
                  ->references('id')
                  ->on('rooms')
                  ->onDelete('cascade');
        });
    }

    /**
     * Reverse the migrations.
     *
     * @return void
     */
    public function down()
    {
        Schema::dropIfExists('orders');
    }
}
